import submitFormView from "./submitFormView.js";

class submitStateView {
  _closeModalButton = document.querySelector(".state__close-modal");
  _stateModal = document.querySelector(".notice--state");
  _stateModalWelcome = document.querySelector(".state--welcome");
  _stateModalOverlay = document.querySelector(".overlay");
  _updateFormButton = document.querySelector(".state__link");

  toggleSubmitStateWindow(name = null) {
    name !== null ? (this._stateModalWelcome.innerHTML = `你好，${name}`) : "";
    this._stateModal.classList.toggle("hidden");
    this._stateModalOverlay.classList.toggle("hidden");
  }

  addHandlerShowWindow(handler) {
    window.addEventListener("load", handler);
  }

  addHandlerCloseModal() {
    this._closeModalButton.addEventListener("click", (e) => {
      location.href = "index.html";
    });
  }

  addHandlerUploadForm(handler) {
    this._updateFormButton.addEventListener("click", (e) => {
      e.preventDefault();
      const oldForm = handler();
      submitFormView.dataEcho(oldForm);

      // 取消弹窗
      this.toggleSubmitStateWindow();
    });
  }
}
export default new submitStateView();
